﻿<Application 
    x:Class="Subsonic.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"       
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
    xmlns:unsupported="clr-namespace:Microsoft.Phone.Controls.Unsupported"
    xmlns:local="clr-namespace:ControlTiltEffect"
    xmlns:sr="clr-namespace:Subsonic.Resources;assembly=Subsonic"
    xmlns:s="clr-namespace:Subsonic;assembly=Subsonic"
    xmlns:sc="clr-namespace:Subsonic.Controls"
    xmlns:u="clr-namespace:Utilities;assembly=Subsonic">
    <!-- Application Resources. -->
    <Application.Resources>
        <ResourceDictionary x:Key="ResourceDictionaries">
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Resources/strings.xaml"></ResourceDictionary>
                <ResourceDictionary Source="Resources/wp7strings.xaml"></ResourceDictionary>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
        
        <DataTemplate x:Key="LongListItemTemplate">
            <sc:MainPivotListItem/>
        </DataTemplate>

        <DataTemplate x:Key="ItemListBoxTemplate">
            <StackPanel x:Name="DataTemplateStackPanel" Orientation="Horizontal">
                <Image x:Name="ItemImage" Visibility="{Binding ItemImageVisibility}" Source="{Binding ItemImage}" Height="75" Width="75" VerticalAlignment="Top" Margin="10,0,20,0"/>
                <StackPanel VerticalAlignment="Center">
                    <TextBlock x:Name="ItemText" Text="{Binding LineOne}" Margin="-2,-13,0,0" Style="{StaticResource PhoneTextExtraLargeStyle}" local:TiltEffect.IsTiltEnabled="True"/>
                    <TextBlock x:Name="DetailsText" Visibility="Collapsed" Text="{Binding LineTwo}" Margin="0,-6,0,3" Style="{StaticResource PhoneTextSubtleStyle}"/>
                </StackPanel>
            </StackPanel>
        </DataTemplate>
        
        <DataTemplate x:Key="NoImageItemListBoxTemplate">
            <StackPanel x:Name="DataTemplateStackPanel" Orientation="Horizontal">
                <StackPanel VerticalAlignment="Center">
                    <TextBlock x:Name="ItemText" Text="{Binding LineOne}" Margin="-2,-13,0,0" Style="{StaticResource PhoneTextExtraLargeStyle}" local:TiltEffect.IsTiltEnabled="True"/>
                    <TextBlock x:Name="DetailsText" Text="{Binding LineTwo}" Margin="0,-6,0,3" Style="{StaticResource PhoneTextSubtleStyle}"/>
                </StackPanel>
            </StackPanel>
        </DataTemplate>

        <DataTemplate x:Key="groupHeaderTemplate">
            <Border Background="{StaticResource PhoneAccentBrush}" Margin="0">
                <TextBlock Text="{Binding Title}" FontSize="40" Foreground="Black"/>
            </Border>
        </DataTemplate>
        <DataTemplate x:Key="groupItemTemplate" >
            <Border Background="{StaticResource PhoneAccentBrush}" Width="99" Height="99" Margin="6">
                <TextBlock Text="{Binding Title}" FontSize="40" Foreground="Black"/>
            </Border>
        </DataTemplate>
        <DataTemplate x:Key="PivotItemTemplate">
            <sc:MediaListBox ItemsSource="{Binding Items}" ItemTemplate="{StaticResource ItemListBoxTemplate}"/>
        </DataTemplate>
        <DataTemplate x:Key="LongListPivotItemTemplate">
            <sc:MediaLongListSelector ItemsSource="{Binding Items}" ItemTemplate="{StaticResource LongListItemTemplate}" GroupHeaderTemplate="{StaticResource groupHeaderTemplate}" GroupItemTemplate="{StaticResource groupItemTemplate}">
                <toolkit:LongListSelector.GroupItemsPanel>
                    <ItemsPanelTemplate>
                        <toolkit:WrapPanel/>
                    </ItemsPanelTemplate>
                </toolkit:LongListSelector.GroupItemsPanel>
            </sc:MediaLongListSelector>
        </DataTemplate>

        <shell:ApplicationBar x:Key="globalApplicationBar">
            <shell:ApplicationBarIconButton x:Name="appbar_button_prev" IconUri="/Images/appbar.transport.rew.rest.png" Text="{StaticResource player_prev}"/>
            <shell:ApplicationBarIconButton x:Name="appbar_button_playpause" IconUri="/Images/appbar.transport.play.rest.png" Text="{StaticResource player_play}"/>
            <shell:ApplicationBarIconButton x:Name="appbar_button_next" IconUri="/Images/appbar.transport.ff.rest.png" Text="{StaticResource player_next}"/>
            <shell:ApplicationBarIconButton x:Name="appbar_button_queue" IconUri="/Images/queue.png" Text="{StaticResource now_playing_queue}"/>

            <shell:ApplicationBar.MenuItems>
                <shell:ApplicationBarMenuItem x:Name="appbar_menu_servers" Text="{StaticResource settings_servers_title}" />
                <shell:ApplicationBarMenuItem x:Name="appbar_menu_settings" Text="{StaticResource main_settings}"/>
                <shell:ApplicationBarMenuItem x:Name="appbar_menu_refresh" Text="{StaticResource player_refresh}"/>
                <shell:ApplicationBarMenuItem x:Name="appbar_menu_help" Text="{StaticResource help_label}"/>
            </shell:ApplicationBar.MenuItems>
        </shell:ApplicationBar>
        
        <Style x:Key="CustomIndeterminateProgressBar" TargetType="ProgressBar">
            <Setter Property="Foreground" Value="{StaticResource PhoneAccentBrush}"/>
            <Setter Property="Background" Value="{StaticResource PhoneAccentBrush}"/>
            <Setter Property="Maximum" Value="100"/>
            <Setter Property="IsHitTestVisible" Value="False"/>
            <Setter Property="Padding" Value="{StaticResource PhoneHorizontalMargin}"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ProgressBar">
                        <unsupported:RelativeAnimatingContentControl HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
                            <unsupported:RelativeAnimatingContentControl.Resources>
                                <ExponentialEase EasingMode="EaseOut" Exponent="1" x:Key="ProgressBarEaseOut"/>
                                <ExponentialEase EasingMode="EaseOut" Exponent="1" x:Key="ProgressBarEaseIn"/>
                            </unsupported:RelativeAnimatingContentControl.Resources>
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates">
                                    <VisualState x:Name="Determinate"/>
                                    <VisualState x:Name="Indeterminate">
                                        <Storyboard RepeatBehavior="Forever" Duration="00:00:04.4">
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="IndeterminateRoot">
                                                <DiscreteObjectKeyFrame KeyTime="0">
                                                    <DiscreteObjectKeyFrame.Value>
                                                        <Visibility>Visible</Visibility>
                                                    </DiscreteObjectKeyFrame.Value>
                                                </DiscreteObjectKeyFrame>
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="DeterminateRoot">
                                                <DiscreteObjectKeyFrame KeyTime="0">
                                                    <DiscreteObjectKeyFrame.Value>
                                                        <Visibility>Collapsed</Visibility>
                                                    </DiscreteObjectKeyFrame.Value>
                                                </DiscreteObjectKeyFrame>
                                            </ObjectAnimationUsingKeyFrames>
                                            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00.0" Storyboard.TargetProperty="X" Storyboard.TargetName="R1TT">
                                                <LinearDoubleKeyFrame KeyTime="00:00:00.0" Value="0.1"/>
                                                <EasingDoubleKeyFrame KeyTime="00:00:00.5" Value="33.1" EasingFunction="{StaticResource ProgressBarEaseOut}"/>
                                                <LinearDoubleKeyFrame KeyTime="00:00:02.0" Value="66.1"/>
                                                <EasingDoubleKeyFrame KeyTime="00:00:02.5" Value="100.1" EasingFunction="{StaticResource ProgressBarEaseIn}"/>
                                            </DoubleAnimationUsingKeyFrames>
                                            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00.2" Storyboard.TargetProperty="X" Storyboard.TargetName="R2TT">
                                                <LinearDoubleKeyFrame KeyTime="00:00:00.0" Value="0.1"/>
                                                <EasingDoubleKeyFrame KeyTime="00:00:00.5" Value="33.1" EasingFunction="{StaticResource ProgressBarEaseOut}"/>
                                                <LinearDoubleKeyFrame KeyTime="00:00:02.0" Value="66.1"/>
                                                <EasingDoubleKeyFrame KeyTime="00:00:02.5" Value="100.1" EasingFunction="{StaticResource ProgressBarEaseIn}"/>
                                            </DoubleAnimationUsingKeyFrames>
                                            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00.4" Storyboard.TargetProperty="X" Storyboard.TargetName="R3TT">
                                                <LinearDoubleKeyFrame KeyTime="00:00:00.0" Value="0.1"/>
                                                <EasingDoubleKeyFrame KeyTime="00:00:00.5" Value="33.1" EasingFunction="{StaticResource ProgressBarEaseOut}"/>
                                                <LinearDoubleKeyFrame KeyTime="00:00:02.0" Value="66.1"/>
                                                <EasingDoubleKeyFrame KeyTime="00:00:02.5" Value="100.1" EasingFunction="{StaticResource ProgressBarEaseIn}"/>
                                            </DoubleAnimationUsingKeyFrames>
                                            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00.6" Storyboard.TargetProperty="X" Storyboard.TargetName="R4TT">
                                                <LinearDoubleKeyFrame KeyTime="00:00:00.0" Value="0.1"/>
                                                <EasingDoubleKeyFrame KeyTime="00:00:00.5" Value="33.1" EasingFunction="{StaticResource ProgressBarEaseOut}"/>
                                                <LinearDoubleKeyFrame KeyTime="00:00:02.0" Value="66.1"/>
                                                <EasingDoubleKeyFrame KeyTime="00:00:02.5" Value="100.1" EasingFunction="{StaticResource ProgressBarEaseIn}"/>
                                            </DoubleAnimationUsingKeyFrames>
                                            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00.8" Storyboard.TargetProperty="X" Storyboard.TargetName="R5TT">
                                                <LinearDoubleKeyFrame KeyTime="00:00:00.0" Value="0.1"/>
                                                <EasingDoubleKeyFrame KeyTime="00:00:00.5" Value="33.1" EasingFunction="{StaticResource ProgressBarEaseOut}"/>
                                                <LinearDoubleKeyFrame KeyTime="00:00:02.0" Value="66.1"/>
                                                <EasingDoubleKeyFrame KeyTime="00:00:02.5" Value="100.1" EasingFunction="{StaticResource ProgressBarEaseIn}"/>
                                            </DoubleAnimationUsingKeyFrames>
                                            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00.0" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="R1">
                                                <DiscreteDoubleKeyFrame KeyTime="0" Value="1"/>
                                                <DiscreteDoubleKeyFrame KeyTime="00:00:02.5" Value="0"/>
                                            </DoubleAnimationUsingKeyFrames>
                                            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00.2" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="R2">
                                                <DiscreteDoubleKeyFrame KeyTime="0" Value="1"/>
                                                <DiscreteDoubleKeyFrame KeyTime="00:00:02.5" Value="0"/>
                                            </DoubleAnimationUsingKeyFrames>
                                            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00.4" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="R3">
                                                <DiscreteDoubleKeyFrame KeyTime="0" Value="1"/>
                                                <DiscreteDoubleKeyFrame KeyTime="00:00:02.5" Value="0"/>
                                            </DoubleAnimationUsingKeyFrames>
                                            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00.6" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="R4">
                                                <DiscreteDoubleKeyFrame KeyTime="0" Value="1"/>
                                                <DiscreteDoubleKeyFrame KeyTime="00:00:02.5" Value="0"/>
                                            </DoubleAnimationUsingKeyFrames>
                                            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00.8" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="R5">
                                                <DiscreteDoubleKeyFrame KeyTime="0" Value="1"/>
                                                <DiscreteDoubleKeyFrame KeyTime="00:00:02.5" Value="0"/>
                                            </DoubleAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                            <Grid>
                                <Grid x:Name="DeterminateRoot" Margin="{TemplateBinding Padding}" Visibility="Visible">
                                    <Rectangle x:Name="ProgressBarTrack" Fill="{TemplateBinding Background}" Height="4" Opacity="0.1"/>
                                    <Rectangle x:Name="ProgressBarIndicator" Fill="{TemplateBinding Foreground}" HorizontalAlignment="Left" Height="4"/>
                                </Grid>
                                <Border x:Name="IndeterminateRoot" Margin="{TemplateBinding Padding}" Visibility="Collapsed">
                                    <Grid HorizontalAlignment="Left">
                                        <Rectangle Fill="{TemplateBinding Foreground}" Height="4" IsHitTestVisible="False" Width="4" x:Name="R1" Opacity="0" CacheMode="BitmapCache">
                                            <Rectangle.RenderTransform>
                                                <TranslateTransform x:Name="R1TT"/>
                                            </Rectangle.RenderTransform>
                                        </Rectangle>
                                        <Rectangle Fill="{TemplateBinding Foreground}" Height="4" IsHitTestVisible="False" Width="4" x:Name="R2" Opacity="0" CacheMode="BitmapCache">
                                            <Rectangle.RenderTransform>
                                                <TranslateTransform x:Name="R2TT"/>
                                            </Rectangle.RenderTransform>
                                        </Rectangle>
                                        <Rectangle Fill="{TemplateBinding Foreground}" Height="4" IsHitTestVisible="False" Width="4" x:Name="R3" Opacity="0" CacheMode="BitmapCache">
                                            <Rectangle.RenderTransform>
                                                <TranslateTransform x:Name="R3TT"/>
                                            </Rectangle.RenderTransform>
                                        </Rectangle>
                                        <Rectangle Fill="{TemplateBinding Foreground}" Height="4" IsHitTestVisible="False" Width="4" x:Name="R4" Opacity="0" CacheMode="BitmapCache">
                                            <Rectangle.RenderTransform>
                                                <TranslateTransform x:Name="R4TT"/>
                                            </Rectangle.RenderTransform>
                                        </Rectangle>
                                        <Rectangle Fill="{TemplateBinding Foreground}" Height="4" IsHitTestVisible="False" Width="4" x:Name="R5" Opacity="0" CacheMode="BitmapCache">
                                            <Rectangle.RenderTransform>
                                                <TranslateTransform x:Name="R5TT"/>
                                            </Rectangle.RenderTransform>
                                        </Rectangle>
                                    </Grid>
                                </Border>
                            </Grid>
                        </unsupported:RelativeAnimatingContentControl>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <ControlTemplate x:Key="MediaFrameTemplate">
            <Grid x:Name="MediaElementContainer" Margin="0,0,0,0">
                <Grid x:Name="ClientArea" Margin="0,0,0,0">
                    <Grid x:Name="ProgressContainer" Margin="0,0,0,0">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="20"/>
                            <RowDefinition Height="*"/>
                        </Grid.RowDefinitions>
                        <ProgressBar Canvas.ZIndex="0" Grid.Row="0"
                            x:Name="customIndeterminateProgressBar"
                            IsIndeterminate="false"
                            Visibility="Collapsed"
                            Style="{StaticResource CustomIndeterminateProgressBar}"
                        />
                    </Grid>
                    <ContentPresenter Margin="0,0,0,0"/>
                </Grid>
                <MediaElement Volume="1.0" Margin="0,0,0,0" Visibility="Collapsed" AutoPlay="False" />
            </Grid>
        </ControlTemplate>

    </Application.Resources>

    <Application.ApplicationLifetimeObjects>
        <!--Required object that handles lifetime events for the application-->
        <shell:PhoneApplicationService 
            Launching="Application_Launching" Closing="Application_Closing" 
            Activated="Application_Activated" Deactivated="Application_Deactivated"/>
    </Application.ApplicationLifetimeObjects>

</Application>
